//
//  YeeKindCollectionView.m
//  YeeShopProject
//
//  Created by CoderYee on 2017/2/28.
//  Copyright © 2017年 CoderYee. All rights reserved.
//

#import "YeeKindCollectionView.h"

@interface YeePrimaryHeaderView : UICollectionReusableView
@property(nonatomic,retain)UILabel    *describeLable;

@end

@implementation YeePrimaryHeaderView

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self=[super initWithFrame:frame])
    {
        [self addOwnViews];
    }
    return self;
}
-(void)addOwnViews
{
    _describeLable=[[UILabel alloc] init];
    _describeLable.font=[UIFont Y_systemFontOfSize:13];
    _describeLable.text=@"男士服装";
    _describeLable.textAlignment=NSTextAlignmentCenter;
    _describeLable.textColor=kBlackColor;
    [self addSubview:_describeLable];
    [_describeLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
        make.height.mas_equalTo(21);
    }];
    UIView *leftView=[[UIView alloc] init];
    [leftView setBackgroundColor:[UIColor grayColor]];
    leftView.alpha=0.3;
    [self addSubview:leftView];
    [leftView mas_makeConstraints:^(MASConstraintMaker *make)
     {   make.right.equalTo(_describeLable.mas_left);
         make.centerY.equalTo(self);
         make.width.mas_equalTo(25);
         make.height.mas_equalTo(1.0f);
     }];
    UIView *rightView=[[UIView alloc] init];
    [rightView setBackgroundColor:[UIColor grayColor]];
    rightView.alpha=0.3;
    [self addSubview:rightView];
    [rightView mas_makeConstraints:^(MASConstraintMaker *make)
     {
         make.left.equalTo(_describeLable.mas_right);
         make.centerY.equalTo(self);
         make.width.mas_equalTo(25);
         make.height.mas_equalTo(1.0f);
     }];

}
@end

@interface YeePrimaryCollectionViewCell : UICollectionViewCell
@property(nonatomic,retain)UILabel       *describeLable;
@property(nonatomic,retain)UIImageView   *iconImageView;


@end

@implementation YeePrimaryCollectionViewCell

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self=[super initWithFrame:frame])
    {
        [self addOwnViews];
    }
    return self;
}
-(void)addOwnViews
{
    _describeLable=[[UILabel alloc] init];
    _describeLable.font=[UIFont Y_systemFontOfSize:13];
    _describeLable.text=@"男士袜子";
    _describeLable.textAlignment=NSTextAlignmentCenter;
    _describeLable.textColor=kBlackColor;
    [self.contentView addSubview:_describeLable];
    [_describeLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.contentView);
        make.height.mas_equalTo(21);
        make.centerX.equalTo(self.contentView);
    }];
    _iconImageView=[[UIImageView alloc] init];
    _iconImageView.contentMode=UIViewContentModeScaleAspectFill;
    _iconImageView.clipsToBounds=YES;
    [_iconImageView setImage:[UIImage imageNamed:@"collect_placehoderimage"]];
    [self addSubview:_iconImageView];
    [_iconImageView mas_makeConstraints:^(MASConstraintMaker *make)
     {
        // make.centerX.equalTo(self);
         make.left.right.equalTo(self.contentView);
         make.bottom.equalTo(_describeLable.mas_top);
         make.top.equalTo(self.contentView);
     }];
    
}
@end


@interface YeeKindCollectionView ()<UICollectionViewDelegate,UICollectionViewDataSource>
{
    
    
}

@end
@implementation YeeKindCollectionView

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self=[super initWithFrame:frame])
    {
        [self addCollectionView];
        _clickSubject=[RACSubject subject];
    }
    return self;
}
-(void)addCollectionView
{
    UICollectionViewFlowLayout *laout=[[UICollectionViewFlowLayout alloc] init];
    laout.minimumLineSpacing=0.0;
    _collectionView=[[UICollectionView alloc] initWithFrame:self.bounds collectionViewLayout:laout];
    [_collectionView setBackgroundColor:[UIColor clearColor]];
    _collectionView.delegate=self;
    _collectionView.dataSource=self;
    _collectionView.showsVerticalScrollIndicator=NO;
    _collectionView.showsHorizontalScrollIndicator=NO;
    [_collectionView registerClass:[YeePrimaryCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([YeePrimaryCollectionViewCell class])];
    [_collectionView registerClass:[YeePrimaryHeaderView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:NSStringFromClass([YeePrimaryHeaderView class])];
    [self addSubview:_collectionView];
    
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 2;
    
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 20;
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
     return   UIEdgeInsetsMake(5.0, 10, 5.0, 10);
    
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
{
    return CGSizeMake(self.width, 40);
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake((kMainScreenWidth/5.0*3.0-30)/2.0, 100);
    
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    YeePrimaryHeaderView *headerView=[collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:NSStringFromClass([YeePrimaryHeaderView class]) forIndexPath:indexPath];
    return headerView;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    YeePrimaryCollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([YeePrimaryCollectionViewCell class]) forIndexPath:indexPath];
    
    return cell;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    
    return 5.0;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout{
    
    return 5.0;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    [_clickSubject sendNext:indexPath];
    
}
@end
